﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KD.Sms.UI_Manager
{
    public partial class frmParms : Form
    {
        public frmParms()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmParms_Load(object sender, EventArgs e)
        {
            gridMain.DataSource = DAL.SqlLite.Main.Instance.DoQueryParmsForEdit();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tools_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
        {
            if (DAL.SqlLite.Main.Instance.DoSaveParms(gridMain))
            {
                DAL.SqlLite.Main.Instance.LogWrite(SysLogType.Login, "成功保存当前参数设置");

                if (MessageBox.Show("操作成功!是否关闭当前窗体?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    this.Close();
            }
            else
                UI.MsgBox.Show(UI.MsgType.Error, "操作失败!请检查输入数据格式是否正确!");
        }

        private void frmParms_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Escape)
                this.Close();
        }

        private void gridMain_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
                DAL.SqlLite.Main.Instance.LogWrite(SysLogType.Login, string.Format("修改系统参数[{0}]项[{1}]值[{2}]  是否保存需结合后续日志", gridMain.Rows[e.RowIndex].Cells["Param_Name"].Value.ToString(), gridMain.Columns[e.ColumnIndex].HeaderText, gridMain.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString()));
        }
    }
}
